Installation

Install via:

devtools::install_github("Puntalytics/puntr")
library(puntr)
library(tidyverse) # always a good idea to do this too

Using puntr with NFL data

Completed seasons

For speed, we’ve already scraped (using nflfastR) and saved punting data for the 1999-2020 seasons. The easiest thing to do is download the puntr-data repo here, and then point puntr::import_punts() to your local copy of the data. You can also download the data directly each time; this takes around 15 minutes.
Import, clean, and calculate as follows:

#punts_raw <- import_punts(1999:2020) # This takes ~15 minutes
punts_raw <- import_punts(1999:2020, local=TRUE, path=your_local_path)
punts_cleaned <- trust_the_process(punts_raw) # clean
punts <- calculate_all(punts_cleaned) # calculate custom Puntalytics metrics 

You now have a dataframe punts where each row is a punt, and each column is a stat relevant to punting (including our custom metrics).

In-progress seasons

The kind folks at nflfastR have set up a convenient SQL-y way to scrape data for in-progress seasons. Rather than redo all of that work, we’ll just share here the code we use for this purpose:

#install.packages("DBI")
#install.packages("RSQLite")
library(DBI)
library(RSQLite)
library(nflfastR)
library(puntr)

update_db()
pbp <- tbl(connection, "nflfastR_pbp")

punts <- pbp %>% filter(punt_attempt==1) %>%
  collect() %>%
  trust_the_process() %>%
  calculate_all()

dbDisconnect(connection)

Comparing punters

To compare punters, continue with

mini <- create_mini(punts)
to get a dataframe where each row is a punter, and each column is an average stat for that punter.

To compare punter seasons, instead use

miniY <- create_miniY(punts)
which gives every unique punter season a row.

To compare punter games, instead use

miniG <- create_miniG(punts)
which gives every unique punter season a row.

These dataframes - punts, mini, miniY and miniG - should serve as a good starting point for any custom analysis you’d like to do, be that using built-in puntr metrics, or your own.

Using puntr with college data

puntr can also handle punting data for college football, piggybacking off of the scraping abilities of the cfbscrapR package. Import and clean as follows:

college_punts <- import_college_punts(2019:2020) %>% # import (calls cfbscrapR behind the scenes)
 college_to_pro() %>% # rename columns to those used by nflfastR
 calculate_all() # calculate as with NFL data

Now we can use the same create_miniY as above to compare college punter seasons (create_mini and create_miniG would also work here, of course.)

miniY_college <- create_miniY(college_punts)